<?php
/**
 * User: YL
 * Date: 2019/09/12
 */

namespace restful\traits;

use Illuminate\Contracts\Container\BindingResolutionException;
use restful\utils\Helper;

trait Instance
{
    /**
     * @var array
     */
    protected static $instances = [];

    /**
     * getInstance
     * @param array $params
     * @return static
     * @throws BindingResolutionException
     */
    public static function getInstance(array $params = [])
    {
        $key = Helper::getKeyByArray($params, __CLASS__);
        if (empty(static::$instances[$key])) {
            static::$instances[$key] = app()->make(__CLASS__, $params);
        }

        return static::$instances[$key];
    }
}
